const fs = require('fs');
const path = require('path');

function scanDir(dir, entry){
    if (fs.existsSync(dir)) {
        let files = fs.readdirSync(dir);
        files.forEach(item => {
            const currentPath = `${dir}/${item}`;
            const stat = fs.statSync(currentPath);
            if (stat.isDirectory()) {
                scanDir(currentPath, entry);
            } else if (stat.isFile()) {
                if (item === 'page.json') {
                    entry[`${dir.replace(path.resolve(__dirname, '../client/pages/'), '')}`] = currentPath.replace('page.json', 'index.js');
                }
            }
        });
    }
}

module.exports = path => {
    let entry = {}
    scanDir(path, entry);
    return entry
}
